package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.sun.deploy.util.StringUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接mq服务器
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Connection con = f.newConnection();
        Channel c = con.createChannel();

        //在mq服务器上，创建消息队列  helloworld
        c.queueDeclare("helloworld",false,false,false,null);

        //向helloworld队列发送消息
        c.basicPublish("", "helloworld", null, "helloworld".getBytes());
        System.out.println("消息已发送");

        c.close();
        con.close();
    }
}

